import asyncio
import time


async def download(url):
    print('准备开始下载······')
    await asyncio.sleep(2)  # 网络请求
    print('下载完成······')


async def main():
    urlList = [
        'http://www.baidu.com',
        'http://www.bilibili.com',
        'http://www.163.com'
    ]

    tasks = []

    for url in urlList:
        d = download(url)
        tasks.append(asyncio.create_task(d))  # 需要将协程对象，转换成 task 对象

    # 一次性启动多个任务（协程）
    t1 = time.time()
    await asyncio.wait(tasks)
    print('共耗时：', time.time() - t1)


if __name__ == '__main__':
    asyncio.run(main())
